package GUI;

import javax.swing.table.*;

import java.util.ArrayList;

import model.*;
import control.*;

public class vehicleTable extends DefaultTableModel
{
	private ArrayList<Vehicle> veh = new ArrayList<Vehicle>();
	
	public vehicleTable()
	{
		
	}
	
	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
	
	public void setVeh(ArrayList<Vehicle> _veh)
	{
		veh = _veh;
		fireTableDataChanged();
	}
	
	public ArrayList<Vehicle> getS()
	{
		return veh;
	}
	
	@Override
	public int getColumnCount()
	{
		return 5;
	}
	
	@Override
	public int getRowCount()
	{
		if(veh == null)
		{
			return 0;
		}
		else
		{
			return veh.size();
		}
	}
	
	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch (column)
		{
			case 0:
				columnName = "License Plate";
				break;
			case 1:
				columnName = "Type";
				break;
			case 2:
				columnName = "Year";
				break;
			case 3:
				columnName = "Color";
				break;
			case 4:
				columnName = "Factory Number";
				break;
		}
		return columnName;
	}
	
	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch (column)
		{
			case 0:
				value = veh.get(row).getLicensePlate();
				break;
			case 1:
				value = veh.get(row).getType();
				break;
			case 2:
				value = veh.get(row).getYear();
				break;
			case 3:
				value = veh.get(row).getColor();
				break;
			case 4:
				value = veh.get(row).getFactoryNr();
		}
		return value;
	}
}
